package com.ruoyi.platform.service.impl;

import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.CreateCache;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.platform.service.BaseManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * @Author: Cola
 * @Date: 2022/8/12 19:59
 **/
public class BaseServiceImpl <M extends BaseMapper<T>, T extends Model<T>> extends ServiceImpl<M, T> implements BaseManager<T> {
    protected final Logger logger = LoggerFactory.getLogger(getClass());
    @Override
    public T get(Serializable id) {
        return this.getById(id);
    }

    @Override
    public void create(T t) {
        this.save(t);
    }

    @Override
    public void update(T t) {
        this.updateById(t);
    }

    @Override
    public void remove(Serializable id) {
        this.removeById(id);
    }

    @Override
    public void removeByIds(String ...ids) {
        this.removeByIds(Arrays.asList(ids));
    }

    @CreateCache(name = "base:codeCache:",expire = 5,timeUnit = TimeUnit.MINUTES,cacheType = CacheType.BOTH)
    public Cache<String,String> codeCache;
}
